package com.qidian.study.dao.impl;

import com.qidian.study.dao.UserBaseDAO;
import com.qidian.study.pojo.User;
import com.qidian.study.pojo.UserBase;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @author 戴着假发的程序员
 * @company 起点编程
 */
public class UserBaseDAOImpl extends BaseDAO implements UserBaseDAO {
    private Connection con;
    private PreparedStatement pst;
    private ResultSet rs;
    @Override
    public int save(UserBase user) {
        return 0;
    }

    @Override
    public UserBase queryByName(String username) {
        UserBase user = null;
        String sql = "select * from v_user_base where user_name = ?";
        try{
            con = getCon();
            pst = con.prepareStatement(sql);
            pst.setString(1,username);
            rs = pst.executeQuery();
            if(rs.next()){
                user = new UserBase();
                user.setNickname(rs.getString("nickname"));
                user.setUserId(rs.getLong("user_id"));
                user.setUsername(rs.getString("user_name"));
                user.setUserpass(rs.getString("user_pass"));
                user.setCreateTime(rs.getString("create_time"));
                user.setModifyTime(rs.getString("modify_time"));
                user.setStatus(rs.getInt("status"));
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            closeAll(rs,pst,con);
        }
        return user;
    }
}
